﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Timers;

namespace XHXTools
{
    /// <summary>
    /// 定时器相关操作————暂时无用
    /// </summary>
    public class TimerOperateX
    {


        /// <summary>
        /// 声明一个方法型，关键字就是delegate
        /// </summary>
        public delegate void DoWhat_Delegate();

        /// <summary>
        /// 用上面的方法类型声明一个对象 func_
        /// </summary>
        DoWhat_Delegate doWhat_;

        /// <summary>
        /// 需要作为参数传递的方法 DoWhat
        /// </summary>
        public void DoWhat()
        {
            Console.WriteLine("123411312");
        }

        /// <summary>
        /// 以 DoWhat_Delegate 为参数的方法 TimingExecution()
        /// 定时执行
        /// </summary>
        /// <param name="doWhat">具体做什么的方法</param>
        /// <param name="ms"></param>
        public void TimingExecution(DoWhat_Delegate doWhat, long ms)
        {
            try
            {
                Timer t = new Timer(ms);
                doWhat_ = doWhat;
                t.Elapsed += (sender, e) => doWhat_();
                t.Start();
            }
            catch (Exception ex)
            {
                string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                string msg = $"时间：【{time}】\n\t 定时任务执行时出现错误，具体信息：{ex.Message}\n";
                RWTextToFile.WriterLog(msg, Path.Combine(AppContext.BaseDirectory,"Logs"), "FtpErrLog.log");
            }
        }
    }
}
